/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#pragma once

#include <QMainWindow>
#include <QLineEdit>
#include <QProgressBar>

#include "ui_auto-mate.h"

#include "installer.h"
#include "appsmodel.h"
#include "logwatcher.h"

/**
	Main application GUI.
*/
class AutoMateUi : public QMainWindow, private Ui::AutoMate {
	Q_OBJECT

	private:
		/** Controllers **/
		Installer installer; /// Installer instance.
		TailWatch *logWatcher; /// Log file watcher.

		/** Gui elements **/
		QLineEdit *searchEdit;
		QProgressBar *downloadProgressBar;

		/**
			Connect actions.
		*/
		void actionsConnect();

		/**
			Setup UI.
		*/
		void setupUi(QMainWindow *widget);

		/**
			Connect UI.
		*/
		void connectUi();

	public slots:

		void updateDataReadProgress(int bytesRead, int totalBytes);
		void resetDownloadAction();
		void updateStatusMessage(QString message);

	public:
		/**
			Default constructor.
			@param parent Parent for Qt heirarchy and memory management.
		*/
		AutoMateUi(QWidget* parent = 0);

	protected slots:
		/**
			Exits the application.
		*/
		void quit();
		/**
			Pops up "About" dialog.
		*/
		void about();
		/**
			Pops Export.. dialog and saves to hard-drive.
		*/
		void save();
		/**
			Pops Import.. dialog and updates selection.
		*/
		void load();
		/**
			Clears selection on applications view.
		*/
		void clearApps();
		/**
			Clears selection on tweaks view.
		*/
		void clearTweaks();
		/**
			Installs the selected versions from the applications view.
		*/
		void install();
		/**
			Applies the selected tweaks from the tweaks view.
		*/
		void tweak();
		/**
			Downloads installers from url.
		*/
		void download();

	signals:
		void downloadVersions(std::vector<Version> versions);
		void abortDownloads();
};
